package com.example.swimmingpool.controller.login;


import com.example.swimmingpool.annotation.RecordLog;
import com.example.swimmingpool.constants.StrConstants;
import com.example.swimmingpool.enums.HttpEnum;
import com.example.swimmingpool.response.CommonResponse;
import com.example.swimmingpool.service.login.LoginService;
import com.example.swimmingpool.vo.login.LoginVo;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class LoginController {

    @Resource
    private LoginService loginService;

    @PostMapping("/login")
    @RecordLog("/login")
    public CommonResponse<String> login(@Valid @RequestBody LoginVo loginVo) {
        var res = loginService.login(loginVo);
        if (HttpEnum.LOGIN_ACCOUNT_ERROR.getMsg().equals(res)) {
            return CommonResponse.fail(StrConstants.EMPTY_STR, res);
        }
        return CommonResponse.success(res, HttpEnum.LOGIN_ACCOUNT_SUCCESS.getMsg());
    }
}
